﻿using RockBus.Composition.Interfaces;
using RockBus.ConfigurationService.Interfaces;
using RockBus.DataContracts;
using RockBus.Logging.Interfaces;
using RockBus.Routing.Interfaces;
using System;
using System.Reflection;
using System.ServiceModel;

namespace RockBus.Services
{
    public partial class ConfigurationService :
        IConfigurationService,
        IConfigurationServiceOneWay
    {
        public static ILogger Logger = DependencyManager.Instance.Resolve<ILogger>();

        public static ISubscriptionManager SubscriptionManager = DependencyManager.Instance.Resolve<ISubscriptionManager>();

        public static ISubscriptionConfigurationManager SubscriptionConfigurationManager = DependencyManager.Instance.Resolve<ISubscriptionConfigurationManager>();

        #region IConfigurationService

        SubscriberConfiguration IConfigurationService.GetSubscriberConfiguration()
        {
            return SubscriptionConfigurationManager.SubscriberConfiguration;
        }

        RockBusAck IConfigurationService.AddOrUpdateSubscribers(AddOrUpdateSubscribersRequest request)
        {
            return SubscriptionManager.AddOrUpdateSubscribers(request);
        }

        RockBusAck IConfigurationService.RemoveSubscribers(RemoveSubscribersRequest request)
        {
            return SubscriptionManager.RemoveSubscribers(request);
        }

        RockBusAck IConfigurationService.RemoveSubscriptions(RemoveSubscriptionsRequest request)
        {
            return SubscriptionManager.RemoveSubscriptions(request);
        }

        PublisherConfiguration IConfigurationService.GetPublisherConfiguration()
        {
            return SubscriptionConfigurationManager.PublisherConfiguration;
        }

        AddOrUpdatePublishersResponse IConfigurationService.AddOrUpdatePublishers(AddOrUpdatePublishersRequest request)
        {
            return SubscriptionManager.AddOrUpdatePublishers(request);
        }

        RockBusAck IConfigurationService.RemovePublishers(RemovePublishersRequest request)
        {
            return SubscriptionManager.RemovePublishers(request);
        }

        RockBusAck IConfigurationService.RemoveReceivePorts(RemoveReceivePortsRequest request)
        {
            return SubscriptionManager.RemoveReceivePorts(request);
        }

        RockBusAck IConfigurationService.RemoveAllSubscribers(RemoveAllSubscribersRequest request)
        {
            return SubscriptionManager.RemoveAllSubscribers(request);
        }

        RockBusAck IConfigurationService.RemoveAllPublishers(RemoveAllPublishersRequest request)
        {
            return SubscriptionManager.RemoveAllPublishers(request);
        }

        #endregion IConfigurationService

        #region IConfigurationServiceOneWay

        void IConfigurationServiceOneWay.AddOrUpdateSubscribers(AddOrUpdateSubscribersRequest request)
        {
            SubscriptionManager.AddOrUpdateSubscribers(request);
        }

        void IConfigurationServiceOneWay.RemoveSubscribers(RemoveSubscribersRequest request)
        {
            SubscriptionManager.RemoveSubscribers(request);
        }

        void IConfigurationServiceOneWay.RemoveSubscriptions(RemoveSubscriptionsRequest request)
        {
            SubscriptionManager.RemoveSubscriptions(request);
        }

        void IConfigurationServiceOneWay.AddOrUpdatePublishers(AddOrUpdatePublishersRequest request)
        {
            SubscriptionManager.AddOrUpdatePublishers(request);
        }

        void IConfigurationServiceOneWay.RemovePublishers(RemovePublishersRequest request)
        {
            SubscriptionManager.RemovePublishers(request);
        }

        void IConfigurationServiceOneWay.RemoveReceivePorts(RemoveReceivePortsRequest request)
        {
            SubscriptionManager.RemoveReceivePorts(request);
        }

        void IConfigurationServiceOneWay.RemoveAllSubscribers(RemoveAllSubscribersRequest request)
        {
            SubscriptionManager.RemoveAllSubscribers(request);
        }

        void IConfigurationServiceOneWay.RemoveAllPublishers(RemoveAllPublishersRequest request)
        {
            SubscriptionManager.RemoveAllPublishers(request);
        }

        #endregion IConfigurationServiceOneWay
    }
}